package com.wzh.chatgpt.data.config;

import cn.bugstack.chatglm.session.OpenAiSession;
import cn.bugstack.chatglm.session.OpenAiSessionFactory;
import cn.bugstack.chatglm.session.defaults.DefaultOpenAiSessionFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: wzh
 * time 2023 12 13 21 50
 **/
@Configuration
@EnableConfigurationProperties(ChatGPTSDKConfigProperties.class)
public class ChatGPTSDKConfig {

    @Bean
    public OpenAiSession openAiSession(ChatGPTSDKConfigProperties chatGPTSDKConfigProperties){
        cn.bugstack.chatglm.session.Configuration configuration=new cn.bugstack.chatglm.session.Configuration();
        configuration.setApiHost(chatGPTSDKConfigProperties.getApiHost());
        configuration.setApiSecretKey(chatGPTSDKConfigProperties.getApiKey());
//        configuration.set
        OpenAiSessionFactory factory=new DefaultOpenAiSessionFactory(configuration);
        return factory.openSession();
    }
}
